﻿using UnityEngine;
using System;
using System.Collections;

public class EventCamera : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}

	RaycastHit hit;
	// Update is called once per frame
	void Update () {
		if( Input.touchCount>=1)
		{
			if(Input.GetTouch(0).phase == TouchPhase.Began)
			{
				Camera currentCamera = GetComponent<Camera>();
				int mask = currentCamera.cullingMask;
				Ray ray = currentCamera.ScreenPointToRay(Input.GetTouch(0).position);
				if( Physics.Raycast(ray, out hit, 1000, mask) )
				{
					Debug.LogError(hit.collider.gameObject.name);
					hit.collider.SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
				}
			}
		}
		
		#if UNITY_EDITOR || UNITY_WEBPLAYER
		if( Input.GetMouseButtonDown(0) )
		{
			Camera currentCamera = GetComponent<Camera>();
			int mask = currentCamera.cullingMask;
			Ray ray = currentCamera.ScreenPointToRay(Input.mousePosition);
			if( Physics.Raycast(ray, out hit, 1000, mask) )
			{
				Debug.LogError(hit.collider.gameObject.name);
				hit.collider.SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
			}
		}
		#endif
	}
}
